package com.easy.order.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.easy.common.bean.OrderItems;
import com.easy.common.bean.Orders;
import com.easy.common.service.IOrderService;
import com.easy.order.mapper.OrderItemsMapper;
import com.easy.order.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class OrderService implements IOrderService {
    @Autowired
    OrderMapper orderMapper;

    @Autowired
    OrderItemsMapper orderItemsMapper;

    @Override
    public Orders insert(Orders orders) {
        orderMapper.insert(orders);
        Orders result=this.getByID(orders.getId());
        return result;
    }

    @Override
    public Orders update(Orders orders) {
        orderMapper.updateById(orders);
        Orders result=this.getByID(orders.getId());
        return result;
    }

    @Override
    public Orders Transact(Integer id) {
        return null;
    }

    @Override
    public Orders cancel(Integer id) {
        return null;
    }

    @Override
    public Orders getByID(Integer id) {
        Orders result=orderMapper.selectById(id);
        return result;
    }

    @Override
    public IPage<Orders> getListByUserID(IPage page, Integer userid) {
        Wrapper wrapper=new QueryWrapper(userid);
        IPage<Orders> result=orderMapper.selectPage(page, wrapper);
        return result;
    }

    @Override
    public IPage<Orders> getListByCustomerID(IPage page, Integer customerid) {
        Wrapper wrapper=new QueryWrapper(customerid);
        IPage<Orders> result=orderMapper.selectPage(page, wrapper);
        return result;
    }

    @Override
    public OrderItems insertItem(OrderItems orderItems) {
        orderItemsMapper.insert(orderItems);
        OrderItems result=orderItemsMapper.selectById(orderItems.getId());
        return result;
    }

    @Override
    public OrderItems updateItem(OrderItems orderItems) {
        orderItemsMapper.updateById(orderItems);
        OrderItems result=orderItemsMapper.selectById(orderItems.getId());
        return result;
    }

    @Override
    public int deleteItem(Integer id) {
        int result=orderItemsMapper.deleteById(id);
        return result;
    }
}
